<!--
 * @Description: 
 * @Author: mmzhang
 * @Date: 2022-03-09 11:28:30
 * @LastEditTime: 2022-03-29 11:43:38
-->
<!-- 地块编辑弹窗 -->
<template>
  <div class='Plate_modal'>
    <Modal v-model="Plateflag" :title="PlateModalTitle" footer-hide width="500">
      <Form ref="PlateformValidate" :model="PlateformValidate" :rules="ruleValidatePlate"
        :label-width="100">
        <Row :gutter="16">
          <Col span="24">
          <FormItem label="地块名称：" prop="plateName">
            <Input type="text" v-model="PlateformValidate.plateName" maxlength="20"></Input>
          </FormItem>
          </Col>
        </Row>
        <Row :gutter="16">
          <Col span="8" offset="15" class="cityList_moudle_footer">
          <Button class="moudle_cancelButton" @click="Plateflag = false">取消</Button>
          <Button type="primary" @click="savePlateStatus('PlateformValidate')">确定</Button>
          </Col>
        </Row>
      </Form>
    </Modal>
  </div>
</template>

<script>
  import productApi from '@/biz/modeling/product'
  export default {
    components: {},
    data() {
      return {
        Plateflag: false,
        PlateModalTitle: '', //地块弹窗title
        PlateformValidate: {
          plateName: '',
        }, //地块名称
        ruleValidatePlate: {
          plateName: [
            { required: true, message: '请填写地块名称', trigger: 'change' },
          ],
        },
      }
    },
    methods: {
      //新增、编辑地块
      newAddPlate(type, data) {
        this.PlateModalTitle = type == 'add' ? '新建地块' : '编辑地块'
        this.Plateflag = true
        if (type == 'edit') {
          this.PlateformValidate = Object.assign({}, this.PlateformValidate, data)
        } else {
          this.PlateformValidate = {
            plateName: '',
          }
        }
      },
      //保存新增、编辑地块
      savePlateStatus() {
        this.$refs.PlateformValidate.validate((valid) => {
          if (valid) {
            this.PlateformValidate.housesId = this.$dt.buildInfo().housesId
            console.log(this.PlateformValidate)
            productApi.plateSaveOrEdit(this.PlateformValidate).then((res) => {
              this.Plateflag = false
              let tips = this.PlateformValidate.plateId ?
                '编辑地块成功' :
                '新增地块成功'
              this.$Message.success(tips)
              this.$refs.PlateformValidate.resetFields()
              this.$emit('saveProductSuccess')
            })
          }
        })
      },
    },
    mounted() {},
  }
</script>
<style lang='scss' scoped>
  .cityList_moudle_footer {
    display: flex;
    justify-content: space-around;
    margin-top: 16px;
  }
</style>